<?php
$tmpRing = RingtonePeer::getRingtoneById($ringtone->getId());
?>
<?php use_helper('Object', 'Validation', 'ObjectAdmin', 'I18N', 'Date') ?>
<?php use_stylesheet('/sf/sf_admin/css/main') ?>

<div id="sf_admin_container">
<form id="sf_admin_edit_form" action="<?php echo url_for('ringtone/saveRbtModerate') ?>" enctype="multipart/form-data" method="post" name="sf_admin_edit_form">
<input id="id" type="hidden" value="<?php echo $ringtone->getId()?>" name="id"/>
<fieldset id="sf_fieldset_none" class="">

<?php	
	if ($sf_request->hasError('ringtone{avatar_path}'))
	{
		echo form_error('ringtone{avatar_path}', array('class' => 'form-error-msg'));	
	}
	else
	{
	  	if ($ringtone->getAvatarPath() == null)
	  	{ 
	  		$avaPath = image_path('default_avatar.gif');
	  	}
	  	else
	  		$avaPath = $ringtone->getFullAvatarPath();
	}		
?>

<div style="height: 120px;margin-bottom:10px; border-bottom: 1px solid #D5DDF3;">
	<div class="form-row">
		<div style="float: left;">
			<img style="width:100px;height:100px;" src="<?php echo $avaPath;?>"/>			
		</div>
		<div style="float: left;">
			<?php include_partial('rbt_player', array('ringtone' => $ringtone)); ?>
			<?php include_partial('origin_player', array('ringtone' => $ringtone)); ?>
		</div>
                <div style ="float: right">
                            <input id = "denyall" type ="hidden" value ="0" name="deny_all"/>
<!--                            <input id = "crbt_status" type ="hidden" name ="ringtone[CRBT]" value ="<?php echo $ringtone->getId(); ?>" style = "width:20px" />-->
                            <?php //echo submit_tag(__('BẢN THU KÉM CHẤT LƯỢNG'),'name=denyAll style="width:200px;height:50px;color:white;background-color:red;font-size:12px;font-weight:bold;text-align:center;margin-right:50px" onclick="deny_all1();return false"') ?>
		</div>
	</div>
	
        <div style="width: 700px; float: left">
            RT: <?php echo $tmpRing[0]['total_download'] ?>
            | RBT: <?php echo $tmpRing[0]['total_set'] ?>
            | Last:
            <?php
                if ($tmpRing[0]['imuzik_last_downloaded'] == NULL)
                    echo 'NULL';
                else
                    echo $tmpRing[0]['imuzik_last_downloaded'] ;
            ?>
            | Hidden:
            <?php
                if ($tmpRing[0]['imuzik_hidden_time'] == NULL)
                    echo 'NULL';
                else
                    echo $tmpRing[0]['imuzik_hidden_time'] ;
            ?>
        </div>
        
</div>

<div id="relation-song">
<?php if(is_array($ringtone_related) && count($ringtone_related) > 0){	?>
	<span class="relation-title">
		Các bài nhạc cùng tên của tác giả:
		<a onclick="showall()" id="showall" style="cursor: pointer;">Show all</a>
	</span>
	<div class="showlist" id ="name1" style="display: none;">
	<table class="relation-tb" width="630px" cellpadding="0" cellspacing="0" border="1">
		<tr>
			<th>Bài hát</th>
			<th>RT</th>
			<th>RBT</th>
			<th>DEL</th>
			<th>Sáng tác</th>
		</tr>
		<?php 	foreach($ringtone_related as $item){ ?>
		<tr>
			<td width="260">
				<div class="player">
					<p><?php echo $item->getName()?></p>
					<object width="250" height="24" id="audioplayer1" data="<?php echo image_path('playa/player.swf');?>" type="application/x-shockwave-flash">
					<param value="player.swf" name="movie"/>
					<param value="playerID=1&amp;soundFile=<?php echo $item->getFullFilePathMp3();?>" name="FlashVars"/>
					<param value="high" name="quality"/>
					<param value="false" name="menu"/>
					<param value="transparent" name="wmode"/>
					</object>
				</div>
			</td>
			<td width="10">
				<?php echo $item->getRtStatus()?>
			</td>
			<td width="10"><?php echo $item->getRbtStatus()?></td>
			<td width="10">
				<?php 
				switch ($item->getOrInitRingtoneStatus()->getRtDelete()){
						case '1':
							echo 'A';
							break;
						case '2':
							echo 'U';
							break;
						case '0':
						default:
							echo 'N';
							break;
					}
				?>
			</td>
			<td><?php echo $item->getComposerName()?></td>
		</tr>
		<?php }	?>
	</table>
	
	</div>
<?php } ?>

<!--  Tất cả các bài đã thành nhạc chuông cùng tên -->
<?php if(is_array($ringtone_related_all) && count($ringtone_related_all) > 0){	?>
	<br clear="all" />
	<span class="relation-title">Các bài nhạc chuông cùng tên:<a onclick="showall_all()" id="showall-all" style="cursor: pointer;">Show all</a></span>
	<div class="showlist" id ="name2" style="display: none;">
	<table class="relation-tb" width="630px" cellpadding="0" cellspacing="0" border="1">
		<tr>
			<th>Bài hát</th>
			<th>RT</th>
			<th>RBT</th>
			<th>DEL</th>
			<th>Sáng tác</th>
		</tr>
		<?php 	foreach($ringtone_related_all as $item){ ?>
		<tr>
			<td width="260">
				<div class="player">
					<p><?php echo $item->getName()?></p>
					<object width="250" height="24" id="audioplayer1" data="<?php echo image_path('playa/player.swf');?>" type="application/x-shockwave-flash">
					<param value="player.swf" name="movie"/>
					<param value="playerID=1&amp;soundFile=<?php echo $item->getFullFilePathMp3();?>" name="FlashVars"/>
					<param value="high" name="quality"/>
					<param value="false" name="menu"/>
					<param value="transparent" name="wmode"/>
					</object>
				</div>
			</td>
			<td width="10">
				<?php echo $item->getRtStatus()?>
			</td>
			<td width="10"><?php echo $item->getRbtStatus()?></td>
			<td width="10">
				<?php 
				switch ($item->getOrInitRingtoneStatus()->getRtDelete()){
						case '1':
							echo 'A';
							break;
						case '2':
							echo 'U';
							break;
						case '0':
						default:
							echo 'N';
							break;
					}
				?>
			</td>
			<td><?php echo $item->getComposerName()?></td>
		</tr>
		<?php }	?>
	</table>
	
	</div>
<?php } ?>
</div>


<div class="form-row">
  <label class="required" for="ringtone_name">Tên Ringtone</label>
  <div class="content">
    <input type="text" size="50" value="<?php echo $ringtone->getName()?>" id="ringtone_name" name="ringtone[name]"/>
  	<a href="#" onclick="showrelation()">Bài liên quan</a>
  </div>
</div>

<div class="form-row">
  <?php echo label_for('ringtone[composer_name]', 'Sáng tác', '') ?>
  <div class="content<?php if ($sf_request->hasError('ringtone{composer_name}')): ?> form-error<?php endif; ?>">
	  <?php if ($sf_request->hasError('ringtone{composer_name}')): ?>
	    <?php echo form_error('ringtone{composer_name}', array('class' => 'form-error-msg')) ?>
	  <?php endif; ?>
	
	  <?php $value = object_input_tag($ringtone, 'getComposerName', array (
		  'size' => 50,
		  'control_name' => 'ringtone[composer_name]',
		)); echo $value ? $value : '&nbsp;' 
	  ?>
	  
	  <?php if ($sf_request->hasError('ringtone{composed_by_user}')): ?>
	    <?php echo form_error('ringtone{composed_by_user}', array('class' => 'form-error-msg')) ?>
	  <?php endif; ?>  
	  <?php if ($ringtone->getComposedByUser() == 1): 
	  			$cbu_checked = 'checked="checked"';
	  		else:
	  			$cbu_checked = '';
	  		endif;
	  ?>
	  <input style="width: 10px;" type="checkbox" name="ringtone[composed_by_user]" value="1" id="ringtone_composed_by_user" <?php echo $cbu_checked ?> onclick="javascript:updateComposerName();"/>
	  Tự sáng tác
	  <input type="hidden" name="creatorname" id ="creatorname" value="<?php echo $ringtone->getCreatorName()?>" />	   
  </div>
</div>

<div class="form-row">
  <label class="required" for="ringtone_description">Mô tả:</label>
  <div class="content">
    <textarea id="ringtone_description" name="ringtone[description]" cols="50" rows="5"> <?php echo $ringtone->getRingtoneExtra()->getDescription(); ?></textarea>
  </div>
</div>

<div class="form-row">
  <label class="required" for="ringtone_category_id">Thể loại:</label>
  <div class="content">
        <?php  echo select_tag('ringtone[category_id]', options_for_select($category_list, $ringtone->getCategoryId()), array('class' => 'full', 'peer_method' => 'getListCategory')); ?>
  </div>
</div>

<div class="form-row">
  <label class="required" for="ringtone_category_id">Hành động:</label>
  <div class="content">
        <?php
        	$list_task =  array(1 => 'Đưa lên top', 2 => 'Đưa ra khỏi top');
        	$value = $ringtone->getTopOrder();
        	
        	if($value != null ){
        		$value = 1;
        	}else{
        		$value = 2;
        	}
        	echo select_tag('ringtone[settop_id]', options_for_select($list_task,$value), array('class' => 'full')); ?>
  </div>
</div>

<br/><div style="border-top: 1px solid #D5DDF3"></div>
<br/>

<div class="form-row" id="rbt-row">
  <label class="required" for="ringtone_rbt_code">RBT ID:</label>
  <div class="content">
    <input type="text" size="10" value="<?php echo $ringtone->getRingtoneExtra()->getRbtId(); ?>" id="ringtone_rbt_id" name="ringtone[rbt_id]"/>
  </div>
</div>

<div id="approve-row" class="form-row">
  	<label for="ringtone_approved" class="required">Chọn đồng bộ:</label>
  	<div class="content">
  		<?php if($ringtone_sys == null){	?>
  		<input type="checkbox" name="syschornize" id="syschornize" value="1" />
  		<?php } else {?>
  		<input type="checkbox" name="syschornize" id="syschornize" value="1" checked="checked" />
  		<?php } ?>
	</div>
</div>

<?php 
	$approve_description = $rtstatus->getRtApproveDescription();
	include_partial('rbt_approve', array('approve_description' => $approve_description, 'ringtone' => $ringtone, 'rtstatus' => $rtstatus, 'list_reasons'=>$list_reasons)) 
?>

<?php	
	$delete_description = $rtstatus->getRbtDeleteDescription();
	include_partial('delete_part', array('delete_description' => $delete_description, 'delete_status' => $ringtone->getOrInitRingtoneStatus()->getRbtDelete(), 'list_reasons'=>$list_reasons)) 
?>
</fieldset>
<?php include_partial('popup_edit_actions', array('ringtone' => $ringtone, 'refresh' => $refresh)) ?>
</form>

</div>

<script>
	showOrHideReasonRow(document.getElementById('delete-status-select'), 'delete_info', 1);

	// thang add
	function showapp(el){
		if(el.value == '1'){
			document.getElementById('approve-status-select').value = '2';
			document.getElementById('approve-status-select').disabled="disabled";
			document.getElementById('approve_reason').disabled="disabled";
			showOrHideReasonRow(el, 'reject_info', 1);
			document.getElementById('approve_description').readonly="readonly";
			document.getElementById('approve_description').value = "Xóa bởi admin";
		}else{
			document.getElementById('approve-status-select').value = '0';
			document.getElementById('approve-status-select').disabled = false;
			document.getElementById('approve_reason').disabled = false;
			showOrHideReasonRow(el, 'reject_info', 999);
			document.getElementById('approve_description').value = "...nhập thông tin mô tả ở đây";
		}
	}
	
	function showrelation(){
		
	    //new Ajax.Updater('relation-song',
	     //       '/ringtone/releation?name='+value,
	    //        {asynchronous:true, evalScripts: true}
	    // );
	    
	    var val = document.getElementById('ringtone_name').value;
	    var ringid  = '<?php echo $ringid ?>';
		$.ajax({
			  url: '/ringtone/relation?name='+val+'&ringid='+ringid,
			  success: function(data) {
			    $('#relation-song').html(data);
			  }
			});
	}

	function showall(){
		if(document.getElementById('name1').style.display=="none"){
			document.getElementById('name1').style.display="block";
			document.getElementById('showall').innerHTML = "Hide";
		}else{
			document.getElementById('name1').style.display="none"
				document.getElementById('showall').innerHTML = "Show all";
		}
	}

	function showall_all(){
		if(document.getElementById('name2').style.display=="none"){
			document.getElementById('name2').style.display="block";
			document.getElementById('showall-all').innerHTML = "HIDEN";
		}else{
			document.getElementById('name2').style.display="none"
				document.getElementById('showall-all').innerHTML = "Show all";
		}
	}
        function deny_all1(){
            if (confirm("Từ chối cả nhạc chuông và nhạc chờ của bài hát này")){
                document.getElementById('denyall').value = "1";
                document.getElementById('sf_admin_edit_form').submit();

            }

        }
</script>
